<template>
  <div>
    <el-container>
      <el-aside width="300px">
        <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>

        <!-- "#dbe1e6", "#10ab0d", "#ff0000" -->
        <el-checkbox-group v-model="checkboxGroup" size="mini" @change="filterStatus">
          <el-checkbox-button label="成功">成功</el-checkbox-button>
          <el-checkbox-button label="失败">失败</el-checkbox-button>
          <el-checkbox-button label="未运行">未运行</el-checkbox-button>
          <el-checkbox-button label="更多" >+</el-checkbox-button>
        </el-checkbox-group>
        <el-checkbox-group
          v-model="checkboxGroupTime"
          size="mini"
          v-show="filterMore"
          @change="filterTime"
        >
          <el-checkbox-button label="快">时间快</el-checkbox-button>
          <el-checkbox-button label="一般">时间一般</el-checkbox-button>
          <el-checkbox-button label="慢">时间慢</el-checkbox-button>
          <el-checkbox-button label="绝望">时间绝望</el-checkbox-button>
        </el-checkbox-group>

        <el-tree
          class="filter-tree"
          :data="data"
          :props="defaultProps"
          :style="{'height':seen_height-120+'px','overflow-y':'auto'}"
          @node-click="showdetailmain"
          :filter-node-method="filterNode"
          ref="tree"
        >
          <span class="custom-tree-node" slot-scope="{ node, data }">
            <!-- <el-popover
    placement="top-start"
    title="标题"
    width="200"
    trigger="hover"
    content="这是一段内容,这是一段内容,这是一段内容,这是一段内容。">
    <div  slot="reference">{{ node.label }}</div>
            </el-popover>-->

            <div style="width:200px;overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;">
              <i
                class="el-icon-success"
                style="
    color: green;
"
                v-show="node.data.status=='成功'"
              ></i>
              <i class="el-icon-error" style="
    color: red;
" v-show="node.data.status=='失败'"></i>
              <i
                class="el-icon-remove"
                style="

    color: cadetblue;
"
                v-show="node.data.status=='未运行'"
              ></i>
              {{ node.label }}
            </div>
            <span></span>
          </span>
        </el-tree>
      </el-aside>
      <el-main
        style="box-shadow: rgba(0, 0, 0, 0.12) 0px 2px 4px, rgba(0, 0, 0, 0.04) 0px 0px 6px;margin-left: 1px;"
      >
        <div v-show="isShowInfo">
          <div>
            <el-tag v-show="showInfo.status=='成功'" disable-transitions type="success">成 功</el-tag>
            <el-tag v-show="showInfo.status=='失败'" disable-transitions type="danger">失 败</el-tag>
            <el-tag v-show="showInfo.status=='未运行'" disable-transitions type="info">未运行</el-tag>

            ({{showInfo.parent}}) {{showInfo.label}}
          </div>
          <el-tabs v-model="activeName" @tab-click="handleClick" v-if="showInfo.status!='未运行'" >
            <el-tab-pane label="概要信息" name="first">
              <div style="    padding-top: 5px;    padding-bottom: 15px;">
                <label>
                  <b>重要等级：</b>
                  <span v-text="showInfo.priority"></span>
                </label>
              </div>
              <div style="    padding-top: 5px;    padding-bottom: 15px;">
                <label>
                  <b>运行时间：</b>
                  <span v-text="set_time(showInfo.start_time)"></span>~<span v-text="set_time(showInfo.end_time)"></span>
                </label>
              </div>
              <div style="    padding-top: 5px;    padding-bottom: 15px;">
                <label>
                  <b>运行耗时：</b><i class="el-icon-time"></i>
                  <span v-text="showInfo.used_time"></span>ms
                </label>
              </div>
              <div style="    padding-top: 5px;    padding-bottom: 15px;">
                <label>
                  <b>核心时间：</b>
                  <span v-text="set_time(showInfo.core_start_time)"></span>~<span v-text="set_time(showInfo.core_end_time)"></span>
                </label>
              </div>
              <div style="    padding-top: 5px;    padding-bottom: 15px;">
                <label>
                  <b>核心耗时：</b><i class="el-icon-time"></i>
                  <span v-text="showInfo.core_used_time"></span>ms
                </label>
              </div>
              <div style="    padding-top: 5px;    padding-bottom: 15px;"  v-if="showInfo.status=='失败'" >
                <label>
                  <b>错误原因：</b><br>
                  <span v-text="showInfo.msg"></span>
                </label>
              </div>

            </el-tab-pane>
            <el-tab-pane label="配置信息" name="second">
              
 <el-table
    :data="globalTableData"
    stripe
    border
    :height=seen_height-170
    style="width: 100%">
    <el-table-column
      prop="name"
      label="参数名"
      width="180">
    </el-table-column>
    <el-table-column
      prop="val"
      label="参数值"
     >
    </el-table-column>

  </el-table>

            </el-tab-pane>
            <el-tab-pane label="运行信息" name="third">运行信息</el-tab-pane>
            <el-tab-pane label="其他" name="fourth">其他</el-tab-pane>
          </el-tabs><div v-else><label><h3>未运行原因：</h3><br><span v-text="showInfo.msg"></span></label></div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>
<script>
// import report_data from "../../static/js/data.js";
export default {
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },

  methods: {
     set_time(str){
  var n = parseInt(str);
  var D = new Date(n);
  var year = D.getFullYear();//四位数年份

  var month = D.getMonth()+1;//月份(0-11),0为一月份
  month = month<10?('0'+month):month;

  var day = D.getDate();//月的某一天(1-31)
  day = day<10?('0'+day):day;

  var hours = D.getHours();//小时(0-23)
  hours = hours<10?('0'+hours):hours;

  var minutes = D.getMinutes();//分钟(0-59)
  minutes = minutes<10?('0'+minutes):minutes;

  var seconds = D.getSeconds();//秒(0-59)
  seconds = seconds<10?('0'+seconds):seconds;
  // var week = D.getDay();//周几(0-6),0为周日
  // var weekArr = ['周日','周一','周二','周三','周四','周五','周六'];

  var now_time = year+'-'+month+'-'+day+' '+hours+':'+minutes+':'+seconds;
  return now_time;
},
    showdetailmain(data, node, v) {
      if (node.level == 2) {
        this.showInfo = data;
        this.showInfo.parent = node.parent.data.label;
        this.tid=data.id
        this.isShowInfo = true;
        console.log(data, node);
      }
      // console.log(a, b, c);
    },
    filterNode(value, data) {
      console.log(value, data);
      var st = false;
      if (!value) st = true;
      else st = data.label.indexOf(value) !== -1;
      if (st) {
        st = false;
        console.log(data.status, data.time);

        for (var i = 0; i < this.checkboxGroup.length; i++) {
          if (data.status == this.checkboxGroup[i]) {
            st = true;
            console.log(1);
          }
        }
        if (st) {
          st = false;
          for (var i = 0; i < this.checkboxGroupTime.length; i++) {
            if (data.time == this.checkboxGroupTime[i]) {
              st = true;
              console.log(2);
            }
          }
        }
      }
      console.log(value, data, st);
      return st;
    },
    filterStatus(val) {
      // console.log(val)
      var has_more = false;
      for (var i = 0; i < val.length; i++) {
        if (val[i] == "更多") {
          has_more = true;
        }
      }
      if (this.filterMore == has_more) {
        this.$refs.tree.filter(this.filterText);
      } else {
        this.filterMore = has_more;
        if (!has_more) {
          this.checkboxGroupTime = ["快", "一般", "慢", "绝望"];
          this.$refs.tree.filter(this.filterText);
        }
      }
    },
    filterTime(val) {
      this.$refs.tree.filter(this.filterText);
    },
    handleClick(tab, event) {
      console.log(tab, event);
      if(tab.name=='second'){
        this.globalTableData=report_data.gloabl_dict[this.tid]

      }
    }
  },

  data() {
    return {
      tid:'',
      globalTableData:[],
      activeName: "first",
      seen_height: document.body.clientHeight,
      isShowInfo: false,
      showInfo: {},
      filterMore: false,
      checkboxGroup: ["成功", "失败", "未运行"],
      checkboxGroupTime: ["快", "一般", "慢", "绝望"],
      filterText: "",
      data: report_data.case_detail_list,
      defaultProps: {
        children: "children",
        label: "label"
      }
    };
  }
};
</script>

<style>
html,
body,
#app {
  height: 100%;
  margin: auto;
}
.el-container {
  height: 100%;
}
</style>